<?php
namespace app\ad\model;
/* *
 * 广告管理
 * */
class adlable extends \app\base\model\AdminModel{
    protected $table = 'ad_content';  //文章表

    public function index($id){
        $times = time();
        $ad = $this->table('ad')->where(array('0'=>'id = '.$id.' and (starttime<='.$times.' and endtime>='.$times.')'))->find();
        if($ad){   
            $adlook = $this->where(array('0'=>'ad ='.$ad['id'].' and starttime<='.$times.' and endtime>='.$times))->select();
            if($adlook){
                foreach ($adlook as $key => $value) {
                    $str[$key]['content'] = $value['content'];
                    $str[$key]['url']     = url('ad/url/index',array('ad'=>$value['id']));
                    $str[$key]['width']   = $ad ['width'];
                    $str[$key]['height']  = $ad ['height'];
                    if($ad['types'] == "SWF"){
                        //$str[$key]['ad']='<embed type="application/x-shockwave-flash" src="'.$value['content'].'" height="'.$value['height'].'" width="'.$value['width'].'" wmode="opaque"></embed>';
                        $str[$key]['ad']='<object data="'.$value['content'].'" type="application/x-shockwave-flash" height="'.$ad['height'].'" width="'.$ad['width'].'" ><param name="movie" value="'.$value['content'].'" /><param name="wmode" value="transparent"/></object>';
                    }elseif ($ad['types'] == "JPG") {
                        $str[$key]['ad']='<a href="'.url('ad/url/index',array('ad'=>$value['id'])).'" target="_blank"><img src="'.$value['content'].'" style="width:'.$ad['width'].'px;height:'.$ad['height'].'px" /></a>';
                    }elseif ($ad['types'] == "TXT") {
                        $str[$key]['ad']='<a href="'.url('ad/url/index',array('ad'=>$value['id'])).'" target="_blank">'.$value['content'].'</a>';
                    }else {
                        $str[$key]['ad'] = $value['content'];
                    }
                }
                return $str;
            }else{
               return FALSE;
            } 
        }else{
            return FALSE;
        }
    } 
}